package com.iyoyi.skinlib;

import android.content.res.Resources;
import android.content.res.XmlResourceParser;

import androidx.annotation.NonNull;

public class SkinResources extends Resources {
    private final Resources mSkinRes;

    SkinResources(Resources base, Resources skin) {
        super(skin.getAssets(), skin.getDisplayMetrics(), skin.getConfiguration());
        mSkinRes = base;
    }

    @NonNull
    @Override
    public String getString(int id) throws NotFoundException {
        String result;
        try {
            result = super.getString(id);
        } catch (NotFoundException e) {
            result = mSkinRes.getString(id);
        }
        return result;
    }

    @NonNull
    @Override
    public XmlResourceParser getLayout(int id) throws NotFoundException {
        XmlResourceParser result;
        try {
            result = super.getLayout(id);
        } catch (NotFoundException e) {
            result = mSkinRes.getLayout(id);
        }
        return result;
    }
}
